<template>
  <div class="header-container">
    <div class="l-content">
      <el-button style="margin-right: 20px;" @click="handleMenu" icon="el-icon-s-unfold" size="mini" circle>
      </el-button>
      <el-breadcrumb separator="/">
        <el-breadcrumb-item v-for="item in tags" :key="item.path" :to="{ path: 'item.path' }">{{
          item.label
        }}</el-breadcrumb-item>

      </el-breadcrumb>
    </div>
    <div class="r-content">
      <el-dropdown @command="handleCommand">
        <span class="el-dropdown-link">
          <img alt="" v-bind:class="avatarClass1" />
        </span>
        <el-dropdown-menu slot="dropdown">
          <el-dropdown-item command="cancel">退出</el-dropdown-item>

        </el-dropdown-menu>
      </el-dropdown>
    </div>
  </div>
</template>

<script>
import Cookie from 'js-cookie'
import { mapState } from 'vuex';
export default {
  data() {
    return { avatarClass1: '', }
  },
  methods: {
    getLogingName1() {
      return this.$store.state.tab.username || JSON.parse(localStorage.getItem('userName'))


    },
    handleCommand(command) {
      if (command === 'cancel') {
        Cookie.remove('token')
        Cookie.remove('menu')
        this.$router.push('/login')
      }
    },
    handleMenu() {
      this.$store.commit('collapseMenu')
    },
  },
  computed: {
    ...mapState({
      tags: state => state.tab.tabList
    })
  },
  mounted() {
    if (this.getLogingName1() === 'Admin') {
      this.avatarClass1 = 'adminAvatar'
    } else {
      this.avatarClass1 = 'userAvatar'
    }
  }
}
</script>
<style lang="less" scoped>
.header-container {
  padding: 0 20px;
  background: #333;
  height: 60px;
  display: flex;
  justify-content: space-between;
  align-items: center;

  .text {
    color: #fff;
    font-size: 14px;
    margin-left: 10px;
  }
}

.r-content {
  img {
    width: 40px;
    height: 40px;
    border-radius: 50%;
  }
}

.adminAvatar {
  background: url(../assets/images/user.jpg);
  background-size: 100% 100%;
}

.userAvatar {
  background: url(../assets/images/user1.jpg);
  background-size: 100% 100%;

}

.l-content {
  display: flex;
  align-items: center;

  /deep/.el-breadcrumb__item {
    .el-breadcrumb__inner {
      font-weight: normal;

      &.is-link {
        color: #666
      }
    }

    &:last-child {
      .el-breadcrumb__inner {
        color: white;
      }
    }
  }


}
</style>